package models

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"hui-hui/AppConfig"
)

var DB *gorm.DB
var err error

func MysqlLink() {
	Dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8&parseTime=True&loc=Local", AppConfig.AppConf.Mysql.User, AppConfig.AppConf.Mysql.Password, AppConfig.AppConf.Mysql.Host, AppConfig.AppConf.Mysql.Port, AppConfig.AppConf.Mysql.Database)
	DB, err = gorm.Open(mysql.Open(Dsn))
	if err != nil {
		panic(err)
	}
	if err = DB.AutoMigrate(&User{}, &Plan{}, &Resa{}); err != nil {
		panic(err)
	}
	fmt.Println("mysql预处理完成")
}
